<?php

namespace rokko {

    /***********************************************************
    * 
    ***********************************************************/
    abstract class RokkoController {
        protected $wpdb;
        protected $model;

        /***********************************************************
        * 
        ***********************************************************/
        public function __construct($pWpdb) {
            $this->wpdb = $pWpdb;
            $this->model = array();
        }


        /***********************************************************
        * Load as many models as needed, then reference them by name through the $this->model member 
        ***********************************************************/
        protected function loadModel($pModel) {
            // TODO: Find a way to make it so a model can be accessed in the controller by $this->MyModelName, instead of through a model[] array
            $this->model[$pModel] = new $pModel($this->wpdb);
        }
        
        
        /***********************************************************
        * 
        ***********************************************************/
        protected function getView($pView, $pData) {
            require_once __DIR__."/../../php/Mustache.php";
            
            $mustache = new \Mustache();
            $tmpl = file_get_contents(__DIR__."/../views/".$pView);
            return $mustache->render($tmpl, $pData);
        }
        
        
        /***********************************************************
        * 
        ***********************************************************/
        protected function render($pView, $pData) {
            echo $this->getView($pView, $pData);
        }
    }
}
